package com.example.teachingSystem.controller;

import com.example.teachingSystem.pojo.entity.Notice;
import com.example.teachingSystem.pojo.form.BasePageQuery;
import com.example.teachingSystem.pojo.form.notice.AddNoticeForm;
import com.example.teachingSystem.pojo.form.notice.UpdateNoticeForm;
import com.example.teachingSystem.service.NoticeService;
import com.example.teachingSystem.utils.result.PageResult;
import com.example.teachingSystem.utils.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/notice")
@Tag(name = "公示模块")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    @PostMapping("/one")
    @Operation(summary = "添加公示", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> addNotice(@RequestBody @Validated AddNoticeForm addNoticeForm) {
        return noticeService.addNotice(addNoticeForm);
    }

    @PutMapping("/one")
    @Operation(summary = "更新公示", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> updateNotice(@RequestBody @Validated UpdateNoticeForm updateNoticeForm) {
        return noticeService.updateNotice(updateNoticeForm);
    }

    @DeleteMapping("/one/{id}")
    @Operation(summary = "删除公示", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> updateNotice(@PathVariable Long id) {
        return noticeService.deleteNotice(id);
    }

    @PostMapping("/active/{id}")
    @Operation(summary = "发布公示", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> publishNotice(@PathVariable Long id) {
        return noticeService.changeNoticeActive(id,true);
    }

    @PutMapping("/active/{id}")
    @Operation(summary = "下架公示", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> cancelNotice(@PathVariable Long id) {
        return noticeService.changeNoticeActive(id,false);
    }

    @GetMapping("/more")
    @Operation(summary = "获取公示", security = {@SecurityRequirement(name = "Authorization")})
    public PageResult<Notice> cancelNotice(BasePageQuery basePageQuery) {
        return noticeService.getNoticePage(basePageQuery);
    }


}